function sort(str) {
  if (str.length == 0) {
    return ""
  }
  let len = str.length
  let result = []
  dfs(str, [], result, len)
  return result
}
function dfs(str, path, result, len) {
  let map = {}            //剪枝 避免出现重复的结果
  if (path.length == len) {
    result.push(path.slice(0).toString(''))
  }
  if (str.length == 0) { return }
  for (let i = 0; i < str.length; i++) {
    if (!map[str[i]]) {
      path.push(str[i])
      map[str[i]] = true
      let nS = str.slice(0, i) + str.slice(i + 1)
      dfs(nS, path, result, len)
      path.pop()
    }
  }
}
console.log(sort('aac'))